﻿using System.ComponentModel.Composition;

namespace PocketBook.ViewModels
{
    [Export(typeof(StringListEditorViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
    public sealed class StringListEditorViewModel : DesignEditor<NoteList>
    {
        private int _selectedIndex;

        public int SelectionIndex
        {
            get { return _selectedIndex; }
            set
            {
                if (value == SelectionIndex) return;

                _selectedIndex = value;
                Refresh();
            }
        }

        public bool CanMoveUp
        {
            get { return SelectionIndex > 0; }
        }

        public bool CanMoveDown
        {
            get { return SelectionIndex >= 0 && SelectionIndex + 1 < Settings.Count; }
        }

        public void MoveUp()
        {
            if (CanMoveUp) Move(SelectionIndex, SelectionIndex - 1);
        }

        public void MoveDown()
        {
            if (CanMoveDown) Move(SelectionIndex, SelectionIndex + 1);
        }

        private void Move(int from, int to)
        {
            Settings.Move(from, to);
            Refresh();
        }
    }
}
